<?php

/**
 * This is the model class for table "xyh_breaking_news".
 *
 * The followings are the available columns in table 'xyh_breaking_news':
 * @property string $id
 * @property string $city_id
 * @property string $user_id
 * @property string $thumb_url
 * @property string $img_url
 * @property string $content
 * @property string $ctime
 * @property string $mtime
 * @property string $dtime
 * @property string $status
 * @property string $is_del
 */
class BreakingNews extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xyh_breaking_news';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('img_url, content', 'required'),
			array('city_id, user_id, ctime, mtime, dtime', 'length', 'max'=>10),
			array('thumb_url', 'length', 'max'=>255),
			array('status, is_del', 'length', 'max'=>1),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, city_id, user_id, thumb_url, img_url, content, ctime, mtime, dtime, status, is_del', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    
                        'Area' => array(self::BELONGS_TO, 'Area', 'city_id'),
                        'User' => array(self::BELONGS_TO, 'User', 'user_id'),
                    
                       //'Alumni' => array(self::HAS_MANY, 'Alumni', 'school_id'),  
                    
                    
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'city_id' => 'City',
			'user_id' => 'User',
			'thumb_url' => 'Thumb Url',
			'img_url' => 'Img Url',
			'content' => 'Content',
			'ctime' => 'Ctime',
			'mtime' => 'Mtime',
			'dtime' => 'Dtime',
			'status' => 'Status',
			'is_del' => 'Is Del',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

                
                if($this->ctime){
                    $tmp = strtotime($this->ctime);
                    $criteria->addCondition("t.ctime >=$tmp");
                }
                
                
               // $criteria->with=array('Alumni');
                
                //$criteria->addCondition('t.parent=5');
                $criteria->addCondition("t.is_del=2");
                
		$criteria->compare('id',$this->id,true);
		$criteria->compare('city_id',$this->city_id,true);
		$criteria->compare('user_id',$this->user_id,true);
		$criteria->compare('thumb_url',$this->thumb_url,true);
		$criteria->compare('img_url',$this->img_url,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('ctime',$this->ctime,true);
		$criteria->compare('mtime',$this->mtime,true);
		$criteria->compare('dtime',$this->dtime,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('is_del',$this->is_del,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return BreakingNews the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
        
        
        public function getImg($src){
            
            $srcNew ='http://'.Yii::app()->params['HTTP_HOST'].'/upload/breaking_news/'.$this->user_id.$src;;
            echo CHtml::image($srcNew,'略缩图',array('width'=>'100','height'=>'50'));
        }
        
         public function getCaina($status){
             
            echo $status==1?'<p class="badge badge-important" >是</p>':'<p class="badge badge-important" >否</p>';        
        }
        
       
        
        
}
